Ext.ns('journal.home');

Ext.QuickTips.init();
Ext.form.Field.prototype.msgTarget = 'side';

// {{{
journal.home.PreferenceDialog = Ext.extend(Ext.Window, (function() {

    var logger = journal.LoggerFactory.getLogger("journal.home.PreferenceDialog");
    logger.debug('journal.home.PreferenceDialog');

    var preferenceForms = [];
    preferenceForms['General'] = {
        id : 'General',
        title : 'General',
        xtype : 'journal.preference.GeneralForm',
        layout : 'anchor',
        frame : true
    };

    return {
        // configurables
        // anything what is here can be configured from outside
        constructor : function(config) {
            config = config || {};
            config.listeners = config.listeners || {};
            journal.home.PreferenceDialog.superclass.constructor.call(this, config);
        },

        // {{{
        initComponent : function() {

            // hard coded config - cannot be changed from outside
            var config = {
                id : 'preference-dialog',
                title : 'Preferences',
                modal : true,
                resizable : true,
                constrain : true,
                maximizable : true,
                closeAction : 'hide',
                closable : true,
                layout : 'border',
                items : [ {
                    id : 'preference-explorer',
                    xtype : 'journal.home.PreferenceExplorerPanel',
                    region : 'west',
                    minWidth : '100',
                    width : '170',
                    split : true,
                    resizable : true
                }, {
                    id : 'preferenceFormPanel',
                    xtype : 'panel',
                    region : 'center',
                    layout : 'fit',
                    items : [ {} ],
                    buttons : [ {
                        text : 'Close',
                        handler : function(btn) {
                            btn.ownerCt.ownerCt.ownerCt.hide();
                        }
                    } ]
                } ]
            };// var config

            // apply config
            Ext.apply(this, Ext.apply(this.initialConfig, config));

            // call parent
            journal.home.PreferenceDialog.superclass.initComponent.apply(this, arguments);

            this.get('preference-explorer').getSelectionModel().on('selectionchange', function(sm, treeNode) {
                if (preferenceForms[treeNode.text] == null) {
                    switch (treeNode.text) {
                    case 'Security':
                        preferenceForms[treeNode.text] = {
                            id : 'Security',
                            title : 'Security',
                            frame : true,
                            user : this.user,
                            layout : 'anchor',
                            xtype : 'journal.preference.SecurityForm'
                        };
                        break;
                    }
                }
                var form = preferenceForms[treeNode.text];
                form.user = this.user;

                var formPanel = this.get('preferenceFormPanel');
                formPanel.remove(0);
                formPanel.setTitle(form.title);
                formPanel.add(form);
                formPanel.doLayout();
            }.createDelegate(this));
        } // e/o function initComponent
    // }}}
    };
})()); // e/o extend

// register xtype
Ext.reg('journal.home.PreferenceDialog', journal.home.PreferenceDialog);
// }}}
